package com.mediatek.factorymode.touchscreen1;

import android.content.Context;
import android.content.Intent;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Paint.Align;
import android.graphics.Paint.Style;
import android.graphics.Rect;
import android.os.Handler;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceHolder.Callback;
import android.view.SurfaceView;

public class DrawCircleView
        extends SurfaceView
        implements SurfaceHolder.Callback
{
    final int RADIUS = 35;
    int h;
    MyRect[] mCircleRects = new MyRect[13];
    SurfaceHolder mHolder = null;
    Paint mPaint;
    int w;

    public DrawCircleView(Context paramContext, AttributeSet paramAttributeSet)
    {
        super(paramContext, paramAttributeSet);
        initPaint();
        this.mHolder = getHolder();
        this.mHolder.addCallback(this);
    }

    private void checkFillAll()
    {
        MyRect[] arrayOfMyRect = this.mCircleRects;
        int j = arrayOfMyRect.length;
        int i = 0;
        while (i < j)
        {
            if (!arrayOfMyRect[i].hasFilled) {
                return;
            }
            i += 1;
        }
        new Handler().postDelayed(new Runnable()
        {
            public void run()
            {
                DrawCircleView.this.getContext().sendBroadcast(new Intent("com.mediatek.factorymode.touchscreen.test.action.finish").putExtra("TestPass", 1));
            }
        }, 500L);
    }

    private void drawCircleRects()
    {
        Canvas localCanvas = this.mHolder.lockCanvas();
        localCanvas.drawColor(-16777216);
        MyRect[] arrayOfMyRect = this.mCircleRects;
        int j = arrayOfMyRect.length;
        int i = 0;
        while (i < j)
        {
            MyRect localMyRect = arrayOfMyRect[i];
            if (localMyRect.hasFilled)
            {
                this.mPaint.setStyle(Paint.Style.FILL);
                this.mPaint.setColor(-16777216);
            } else {
                this.mPaint.setStyle(Paint.Style.FILL);
                this.mPaint.setColor(-7829368);
                localCanvas.drawRect(localMyRect.rect, this.mPaint);
                this.mPaint.setTextSize(this.h / 2);
                this.mPaint.setColor(-1);
                this.mPaint.setTextAlign(Paint.Align.CENTER);
                localCanvas.drawText(localMyRect.text, localMyRect.rect.centerX(), localMyRect.rect.centerY(), this.mPaint);
            }
            i += 1;

        }
        this.mHolder.unlockCanvasAndPost(localCanvas);
    }

    private void initCircleRects()
    {
        int k = getMeasuredWidth();
        int i = getMeasuredHeight();
        this.w = (k / 6);
        this.h = (i / 15);
        if (i % 10 == 0) {}
        {
            Log.i("DrawCircleView", String.format("____setCircleRects(...)______measure width: %d, measure height : %d", new Object[] { Integer.valueOf(k), Integer.valueOf(i) }));
            int j = 0;
            while (j < this.mCircleRects.length)
            {
                this.mCircleRects[j] = new MyRect();
                this.mCircleRects[j].text = ("" + j);
                j += 1;
            }
            i = i / 10 * 10;
        }
        this.mCircleRects[0].rect = new Rect(0, 0, this.w, this.h);
        this.mCircleRects[1].rect = new Rect(k / 2 - this.w / 2, 0, k / 2 + this.w / 2, this.h);
        this.mCircleRects[2].rect = new Rect(k - this.w, 0, k, this.h);
        this.mCircleRects[3].rect = new Rect(k / 4 - this.w / 2, i / 4 - this.h / 2, k / 4 + this.w / 2, i / 4 + this.h / 2);
        this.mCircleRects[4].rect = new Rect(k * 3 / 4 - this.w / 2, i / 4 - this.h / 2, k * 3 / 4 + this.w / 2, i / 4 + this.h / 2);
        this.mCircleRects[5].rect = new Rect(0, i / 2 - this.h / 2, this.w, i / 2 + this.h / 2);
        this.mCircleRects[6].rect = new Rect(k / 2 - this.w / 2, i / 2 - this.h / 2, k / 2 + this.w / 2, i / 2 + this.h / 2);
        this.mCircleRects[7].rect = new Rect(k - this.w, i / 2 - this.h / 2, k, i / 2 + this.h / 2);
        this.mCircleRects[8].rect = new Rect(k / 4 - this.w / 2, i * 3 / 4 - this.h / 2, k / 4 + this.w / 2, i * 3 / 4 + this.h / 2);
        this.mCircleRects[9].rect = new Rect(k * 3 / 4 - this.w / 2, i * 3 / 4 - this.h / 2, k * 3 / 4 + this.w / 2, i * 3 / 4 + this.h / 2);
        this.mCircleRects[10].rect = new Rect(0, i - this.h, this.w, i);
        this.mCircleRects[11].rect = new Rect(k / 2 - this.w / 2, i - this.h, k / 2 + this.w / 2, i);
        this.mCircleRects[12].rect = new Rect(k - this.w, i - this.h, k, i);
    }

    private void initPaint()
    {
        this.mPaint = new Paint();
        this.mPaint.setAntiAlias(true);
        this.mPaint.setColor(-7829368);
        this.mPaint.setStyle(Paint.Style.FILL);
    }

    public boolean onTouchEvent(MotionEvent paramMotionEvent)
    {
        if (paramMotionEvent.getAction() == 0)
        {
            int j = (int)paramMotionEvent.getX();
            int k = (int)paramMotionEvent.getY();
            MyRect[] arrayOfMyRect = this.mCircleRects;
            int m = arrayOfMyRect.length;
            int i = 0;
            while (i < m)
            {
                MyRect localMyRect = arrayOfMyRect[i];
                if (localMyRect.rect.contains(j, k)) {
                    localMyRect.hasFilled = true;
                }
                i += 1;
            }
            drawCircleRects();
            checkFillAll();
        }
        return super.onTouchEvent(paramMotionEvent);
    }

    public void surfaceChanged(SurfaceHolder paramSurfaceHolder, int paramInt1, int paramInt2, int paramInt3) {}

    public void surfaceCreated(SurfaceHolder paramSurfaceHolder)
    {
        initCircleRects();
        drawCircleRects();
    }

    public void surfaceDestroyed(SurfaceHolder paramSurfaceHolder) {}

    private class MyRect
    {
        boolean hasFilled;
        Rect rect;
        String text;

        private MyRect() {}
    }
}
